#-*- coding: utf-8 -*-
# Autor : Pedro Lopes
# Data: 7 - 10 - 2013

import math
import sys
from random import *
from math import atan2,atan,sqrt


lista = ['a','b','c']
it = iter(lista)
#print it
x1 = it.next()
#print x1
x2 = it.next()
#print x2

lista1 = ['a','b','c','d','e']
it = iter(lista1)
x = it.next()

#while it:
#    print x
#    x = it.next()


lista_linhas = ['     uma','  duas','   tres']

it = (linha.strip() for linha in lista_linhas)
print it.next() + it.next()+it.next()
lista = [linha.strip() for linha in lista_linhas if len(linha) > 7]
print lista

total_letras = sum(len(linha.strip()) for linha in lista_linhas)
print "total letas{0}".format(total_letras)


def gerar_cubos(N):
    for i in range(N):
        yield i ** 3

gen = gerar_cubos(5)
print gen.next()
print gen.next()
print gen.next()
print gen.next()
print gen.next()

for y in gerar_cubos(5):
    print y

def gerar_quad(N):
    for i in range(N):
        yield i**2
def raiz(x,y):
    return math.sqrt(x+y)

lista = map(raiz,gerar_cubos(5),gerar_quad(5))
i = 0
while i < 5:
    print i,'->', math.sqrt(i**3 + i**2),'==',lista[i]
    i +=1

def f(x):
    if len(x) %2 - 1:
        return x.lower()
    else:
        return x.upper()
expressao = lambda x: x.lower() if len(x) %2 -1 else x.upper()

lista = ['Lisboa', 'Caracas', 'Madrid', 'Londres', 'Berlin', 'Paris']
lista_out1 = map(expressao,lista)
lista_out2 = map(f, lista)

print lista_out1
print lista_out2

lista1 = [1,2,3,2,4,5,4,5,5,1,3]
lista2 = [x for x in set(lista1)]
print lista2

s1 = {'a','b','c','d','e'}
s2 = {'a','b'}

print s1 & s2 , s1 ^ s2 , s1| s2
print s1.union(s2) , s1.intersection(s2)

d1 = {'P1':15,'P2':13,'Matemática':12,'LP':17}
d1['algebra'] = 13
media = 0.0
c = 0
for valor in d1.itervalues():
    media += valor
    c+=1
media /=c
print 'media=', media

for chave,valor in d1.iteritems():
    print chave,valor

print sys.path

lista = [uniform(0,100) for k in xrange(10)]
lista2 = map(lambda x,y: (round(x), round(atan2(x,y)*180/math.pi)),
             map(sqrt,lista),map(lambda x:x**0.5,lista))
print lista2
for raiz,grau in lista2:
    print 'raiz =', raiz, "graus =", grau



        
